package test_model_base;



import java.sql.Date;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.servlet.model.base.Area;
import com.servlet.model.base.Experience;
import com.servlet.model.base.Sector;

public class ExperienceTest extends TestCase {
	private Experience experience;
	private Area area;
	private Sector sector;
	@Before
	public void setUp() throws Exception {
		super.setUp();
		area = new Area(91400, "france", "orsay");
		sector = new Sector();
		experience = new Experience("jialin.liu@u-psud.fr", "CEA", 
				(Date) Date.valueOf("2011-05-09"), (Date) Date.valueOf("2011-08-09"), 
				"programmeur", sector, "stage", area);
	}

	@After
	public void tearDown() throws Exception {
		area = null;
		sector = null;
		experience = null;
	}

	@Test
	public void testExperience() {
		experience = new Experience();
		Assert.assertNull(experience.getDescription());
		Assert.assertNull(experience.getEmail());
		Assert.assertNull(experience.getEnterprise());
		Assert.assertNull(experience.getPost());
		Assert.assertNull(experience.getActivityDomain());
		Assert.assertNull(experience.getArea());
		Assert.assertNull(experience.getDateBegin());
		Assert.assertNull(experience.getDateEnd());
		Assert.assertEquals(false, experience.getIs_modified_activity_domain());
		Assert.assertEquals(false, experience.getIs_modified_area());
		Assert.assertEquals(false, experience.getIs_modified_date_begin());
		Assert.assertEquals(false, experience.getIs_modified_date_end());
		Assert.assertEquals(false, experience.getIs_modified_descriptionn());
		Assert.assertEquals(false, experience.getIs_modified_enterprise());
		Assert.assertEquals(false, experience.getIs_modified_post());
	}

	@Test
	public void testExperienceStringStringDateDateStringSectorStringArea() {
		experience = new Experience("jialin.liu@propig.m", "CNRS", 
				(Date) Date.valueOf("2011-09-01"), (Date) Date.valueOf("2012-02-01"), 
				"chercheur", new Sector(), "stage", new Area(91119, "chine", "gif"));
		Sector s = new Sector();
		Assert.assertEquals("stage", experience.getDescription());
		Assert.assertEquals("jialin.liu@propig.m", experience.getEmail());
		Assert.assertEquals("CNRS", experience.getEnterprise());
		Assert.assertEquals("chercheur", experience.getPost());
		Assert.assertEquals(26, experience.getActivityDomain().getSector());
		Assert.assertEquals(("91119chinegif").hashCode(), experience.getArea().getHCode());
		Assert.assertEquals((Date) Date.valueOf("2011-09-01"), experience.getDateBegin());
		Assert.assertEquals((Date) Date.valueOf("2012-02-01"), experience.getDateEnd());
		Assert.assertEquals(false, experience.getIs_modified_activity_domain());
		Assert.assertEquals(false, experience.getIs_modified_area());
		Assert.assertEquals(false, experience.getIs_modified_date_begin());
		Assert.assertEquals(false, experience.getIs_modified_date_end());
		Assert.assertEquals(false, experience.getIs_modified_descriptionn());
		Assert.assertEquals(false, experience.getIs_modified_enterprise());
		Assert.assertEquals(false, experience.getIs_modified_post());
	}

	@Test
	public void testGetEmail() {
		Assert.assertEquals("jialin.liu@u-psud.fr", experience.getEmail());
	}

	@Test
	public void testGetEnterprise() {
		Assert.assertEquals("CEA", experience.getEnterprise());
	}

	@Test
	public void testGetDateBegin() {
		Assert.assertEquals((Date) Date.valueOf("2011-05-09"), experience.getDateBegin());
	}

	@Test
	public void testGetDateEnd() {
		Assert.assertEquals( (Date) Date.valueOf("2011-08-09"), experience.getDateEnd());
	}

	@Test
	public void testGetPost() {
		Assert.assertEquals( "programmeur", experience.getPost());
	}

	@Test
	public void testGetActivityDomain() {
		Assert.assertEquals(26, experience.getActivityDomain().getSector());
	}

	@Test
	public void testGetDescription() {
		Assert.assertEquals("stage", experience.getDescription());
	}

	@Test
	public void testGetArea() {
		Assert.assertEquals(area, experience.getArea());
	}

	@Test
	public void testGetIs_modified_enterprise() {
		Assert.assertEquals(false, experience.getIs_modified_enterprise());
		experience.setEnterprise("CNRS");
		Assert.assertEquals(true, experience.getIs_modified_enterprise());
	}

	@Test
	public void testGetIs_modified_area() {
		Assert.assertEquals(false, experience.getIs_modified_area());
		experience.setArea(new Area(91119, "chine", "gif") );
		Assert.assertEquals(true, experience.getIs_modified_area());
	}

	@Test
	public void testGetIs_modified_post() {
		Assert.assertEquals(false, experience.getIs_modified_post());
		experience.setPost("chercheur");
		Assert.assertEquals(true, experience.getIs_modified_post());
	}

	@Test
	public void testGetIs_modified_activity_domain() {
		Assert.assertEquals(false, experience.getIs_modified_activity_domain());
		experience.setActivityDomain(new Sector("Construction", true));
		Assert.assertEquals(true, experience.getIs_modified_activity_domain());
	}

	@Test
	public void testGetIs_modified_descriptionn() {
		Assert.assertEquals(false, experience.getIs_modified_descriptionn());
		experience.setDescription("description");
		Assert.assertEquals(true, experience.getIs_modified_descriptionn());
	}

	@Test
	public void testGetIs_modified_date_begin() {
		Assert.assertEquals(false, experience.getIs_modified_date_begin());
		experience.setDateBegin((Date) Date.valueOf("2011-09-01"));
		Assert.assertEquals(true, experience.getIs_modified_date_begin());
	}

	@Test
	public void testGetIs_modified_date_end() {
		Assert.assertEquals(false, experience.getIs_modified_date_end());
		experience.setDateEnd((Date) Date.valueOf("2011-11-01"));
		Assert.assertEquals(true, experience.getIs_modified_date_end());
	}

	@Test
	public void testSetIs_modified_enterprise() {
		experience.setIs_modified_enterprise(true);
		Assert.assertEquals(true, experience.getIs_modified_enterprise());
	}

	@Test
	public void testSetIs_modified_area() {
		experience.setIs_modified_area(true);
		Assert.assertEquals(true, experience.getIs_modified_area());
	}

	@Test
	public void testSetIs_modified_post() {
		experience.setIs_modified_post(true);
		Assert.assertEquals(true, experience.getIs_modified_post());
	}

	@Test
	public void testSetIs_modified_activity_domain() {
		experience.setIs_modified_activity_domain(true);
		Assert.assertEquals(true, experience.getIs_modified_activity_domain());
	}

	@Test
	public void testSetIs_modified_descriptionn() {
		experience.setIs_modified_descriptionn(true);
		Assert.assertEquals(true, experience.getIs_modified_descriptionn());
	}

	@Test
	public void testSetIs_modified_date_begin() {
		experience.setIs_modified_date_begin(true);
		Assert.assertEquals(true, experience.getIs_modified_date_begin());
	}

	@Test
	public void testSetIs_modified_date_end() {
		experience.setIs_modified_date_end(true);
		Assert.assertEquals(true, experience.getIs_modified_date_end());
	}

	@Test
	public void testSetEnterprise() {
		experience.setEnterprise("CNRS");
		Assert.assertEquals(true, experience.getIs_modified_enterprise());
		Assert.assertEquals("CNRS", experience.getEnterprise());
	}

	@Test
	public void testSetDateBegin() {
		experience.setDateBegin((Date) Date.valueOf("2011-09-01"));
		Assert.assertEquals(true, experience.getIs_modified_date_begin());
		Assert.assertEquals((Date) Date.valueOf("2011-09-01"), experience.getDateBegin());
	}

	@Test
	public void testSetDateEnd() {
		experience.setDateEnd((Date) Date.valueOf("2011-10-01"));
		Assert.assertEquals(true, experience.getIs_modified_date_end());
		Assert.assertEquals((Date) Date.valueOf("2011-10-01"), experience.getDateEnd());
	}

	@Test
	public void testSetPost() {
		experience.setPost("chercheur");
		Assert.assertEquals(true, experience.getIs_modified_post());
		Assert.assertEquals("chercheur", experience.getPost());
	}

	@Test
	public void testSetActivityDomain() {
		Sector s = new Sector("Construction", true);
		experience.setActivityDomain(s);
		Assert.assertEquals(true, experience.getIs_modified_activity_domain());
		Assert.assertEquals(s, experience.getActivityDomain());
	}

	@Test
	public void testSetDescription() {
		experience.setDescription("description");
		Assert.assertEquals(true, experience.getIs_modified_descriptionn());
		Assert.assertEquals("description", experience.getDescription());
	}

	@Test
	public void testSetArea() {
		Area a = new Area(91119, "chine", "gif");
		experience.setArea(a );
		Assert.assertEquals(true, experience.getIs_modified_area());
		Assert.assertEquals(a, experience.getArea());
	}

	@Test
	public void testGenerateInsertSQL() {
		Assert.assertEquals("INSERT INTO experience VALUES ('jialin.liu@u-psud.fr' ,'CEA' ,'2011-05-09' ," +
				"'2011-08-09', 'programmeur', 'Autre', 'stage' ," + ("91400franceorsay").hashCode() + ")",
				experience.generateInsertSQL());
	}

	@Test
	public void testGenerateDeleteSQL() {
		Assert.assertEquals("DELETE FROM experience WHERE email='jialin.liu@u-psud.fr' AND enterprise='CEA' AND date_begin='2011-05-09'",
				experience.generateDeleteSQL());
	}

}
